package cn.web.management.web.servlet.inform.admin;

import cn.web.management.service.general.AdminQuery;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "queryPersonalInformServlet", value = "/queryPersonalInformServlet")
public class queryPersonalInformServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    /**
     * @description: 管理员不同方式查询用户信息
     * @paramName: [req, resp]
     * @paramType: [javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse]
     * @returnType: void
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8;");
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        String queryWay = req.getParameter("queryWay");
        String queryno = req.getParameter("queryno");
        AdminQuery adminQuery = new AdminQuery();
        String personalInform = "";

        if (queryWay.equals("all")) {
//        查询所有员工信息
            personalInform = adminQuery.findAllPersonalInform(page,limit);
        }
        else if (queryWay.equals("accordance_employno")){
//            按照员工号查询
            personalInform = adminQuery.findPersonalInform(queryno, page, limit);
        }
        else if (queryWay.equals("accordance_departmentno")){
//            按照部门号查询
            personalInform = adminQuery.findDepartmentPersonalInform(queryno,page,limit);
        }
        else{
//            按照小组号查询
            personalInform = adminQuery.findGroupPersonalInform(queryno,page,limit);
        }
        resp.getWriter().write(personalInform);
    }
}
